package com.adl.hotelmanage.servlet;

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.adl.hotelmanage.dao.DbInquire;
import com.adl.hotelmanage.po.BookRoom;
import com.adl.hotelmanage.po.RoomInfo;
import com.google.gson.Gson;

/**
 * Servlet implementation class ceshi
 */
@WebServlet("/ceshi")
public class ceshi extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ceshi() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=UTF-8");

		List<BookRoom> bookroomls = new ArrayList<BookRoom>();
		String sql = "select * from t_bookroom";
		ResultSet bookroomrs = DbInquire.inquire(sql);
		String json = null;
		try {
			while (bookroomrs.next()) {
				BookRoom bookroom = new BookRoom();
				//bookroom.setBookroom_id(Integer.parseInt(bookroomrs.getString("bookroom_id")));
				bookroom.setBookroom_roomid(bookroomrs.getString("bookroom_roomid"));
				bookroom.setBookroom_roomtype(bookroomrs.getString("bookroom_roomtype"));
				bookroom.setBookroom_liveintime(bookroomrs.getString("bookroom_liveintime"));
				bookroom.setBookroom_outtime(bookroomrs.getString("bookroom_outtime"));
				bookroomls.add(bookroom);
				Gson gson = new Gson();
				 json = gson.toJson(bookroomls);
				 System.out.println("json="+ json);
				 request.setAttribute("bookroomlist", bookroomls);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		response.getWriter().print(json);
		response.getWriter().flush();
		response.getWriter().close();
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
	}

}
